package com.jgzx.exception;

import com.jgzx.common.R;
import com.jgzx.common.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jackesy
 * @className: Error404Controller
 * @description: 自定义404异常处理
 * @create 2020/12/4 0004 18:46
 **/
@Slf4j
@RestController
public class Error404Controller implements ErrorController {


    @Override
    public String getErrorPath() {
        return "/error";
    }

    /**
     * 404异常处理
     *
     * @param request
     * @return
     */
    @RequestMapping("/error")
    public R handlerError(HttpServletRequest request) {
        log.error("404请求资源：request_uri：{}", request.getRequestURI());
        return R.fail(ResultCode.NOT_FOUND);
    }

}
